package cn.e3mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.e3mall.common.pojo.EasyUIDataGridResult;
import cn.e3mall.mapper.TbItemMapper;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemExample;
import cn.e3mall.service.ItemService;
@Service
@Transactional
public class ItemServiceImpl implements ItemService{


	@Autowired
	private TbItemMapper itemMapper;
	
	@Override
	public TbItem getTbItemById(long id) {
		TbItem tbItem = itemMapper.selectByPrimaryKey(id);
		return tbItem;
	}
	
	//分页查询商品列表
	public EasyUIDataGridResult getItemList(int page ,int rows){
		
		//设置分页信息
		PageHelper.startPage(page, rows);
		//查询
		TbItemExample example =new TbItemExample();
		List<TbItem> list = itemMapper.selectByExample(example);
		
		//创建easyUIDataGridResult 返回
		EasyUIDataGridResult easyUIDataGridResult = new EasyUIDataGridResult();
		
		easyUIDataGridResult.setRows(list);
		//创建pageinfo 取分页的信息
		PageInfo<TbItem> pageInfo = new PageInfo<>(list);
		
		//获取总记录数 添加到easyUIDataGridResult
		easyUIDataGridResult.setTotal(pageInfo.getTotal());
		
		//返回easyUIDataGridResult
		return easyUIDataGridResult;
		
	}
	
	
}
